<template>
  <div class="LorR-model verify-model">
    <input
      class="LorR-txt"
      v-model="verifyEmail"
      type="text"
      placeholder="请输入您的邮箱"
    />
    <div class="login-verification">
      <input
        class="LorR-txt"
        v-model="verifyCode"
        type="text"
        placeholder="邮箱所收验证码"
      />
      <input
        class="LorR-btn"
        @click="sendVerification()"
        type="button"
        value="发 送"
      />
    </div>
    <label class="LorR-label">
      <a href="javascript:;" @click="toPwdLogin()">密码登录</a>
    </label>
    <input class="LorR-btn" @click="verify()" type="submit" value="登 录" />
  </div>
</template>

<script>
import http from "@/utils/http.js";
import global from "@/components/Global";
export default {
  data() {
    return {
      verifyEmail: "",
      verifyCode: "",
    };
  },
  methods: {
    toPwdLogin() {
      this.$emit("PL");
    },
    sendVerification: global._debounce(function () {
      const req = {
        mail: this.verifyEmail,
      };
      if (!global.reEmail.test(req.mail)) {
        this.$message.error("邮箱格式错误");
        return;
      }
      http.post("/login/verification", req).then((res) => {
        res;
      });
    }),
    verify: global._debounce(function () {
      const req = {
        mail: this.verifyEmail,
        verification: this.verifyCode,
      };
      if (!global.reEmail.test(req.mail)) {
        this.$message.error("邮箱格式错误");
        return;
      }
      http.post("/login/verificationLogin", req).then((res) => {
        if (res.data.code === 1) {
          console.log(obj.message);
          this.$message.error(obj.message);
          return;
        }
        let obj = res.data.data;
        this.$store.state.id = obj.id;
        this.$store.state.alipay = obj.alipay;
        this.$store.state.username = obj.username;
        this.$store.state.mail = obj.mail;
        this.$store.state.address = obj.contactaddress;
        this.$emit("sucess");
      });
    }),
  },
};
</script>

<style>
</style>